import axios from 'axios'

// 获取用户列表
export const getUsers = () => dispatch => {
  axios.get('/api/users').then(ret => {
    let data = ret.data.data
    dispatch({
      type: 'getusers',
      payload: data
    })
  })
}


// 根据用户id返回对应用户信息
export const getIdToInfo = id => dispatch => {
  axios.get('/api/users/' + id).then(ret => {
    let data = ret.data.data
    dispatch({
      type: 'getuserinfo',
      payload: data
    })
  })
}

// 根据用户来修改id
export const setUserinfo = (id, userinfo) => dispatch => {
  axios.put('/api/users/' + id, userinfo).then(ret => {
    let data = ret.data.data
    dispatch({
      type: 'setUserinfo',
      payload: data
    })
  })
}

// 删除
export const deleteUser = (id,index) => dispatch => {
  /* axios.delete('/api/users/' + id).then(ret => {
    dispatch({
      type: 'deleteUser',
      payload: index
    })
  }) */
  dispatch({
    type: 'deleteUser',
    payload: index
  })
}

